<?php

/**
 * This controller contains with homepage and call page content by post 
 *
 * @package             The IM CMS By Yii
 * @author              Intelligent Millionaire
 * @link                http://www.the-im.com
 * @version		1.0.0 
 * 
 */
class HomeController extends Controller {
    

    public $layout = 'main-admin';

    /**
     *  ActionIndex is default home page 
     *  if you need to redirect to your homepage by modifying 'config/params.php'
     * 	and set homepage value in PageRedirect array and  if you need to redirect
     *  to different page when user logged in you have to  set memberpage value in PageRedirect array
     * 
     */
    
    public function actionIndex() {
        
        $homepage = Common::getOptionValue('pageredirect','homepage');
        $member = Common::getOptionValue('pageredirect','memberpage');
        
        if (!Yii::app()->user->isGuest && $member)
            $this->redirect($member);
        elseif (!$member)
            $this->redirect($homepage);
        elseif ($homepage)
            $this->redirect($homepage);

        if (Yii::app()->user->isGuest && Common::getOptionValue('modulelist','member'))
            $this->layout = 'main-guest';
        
        $this->render('index');
    }

     /**
     *  ActionPage is view of post content as dynamic page content
     *  if you need to render any content page. You just insert your content to post table
     *  and name your post. This action need $slug parameter to query post table by  post name as slug
     *  You need send $slug parameter by url as exmaple '/home/yourslug' 
     * Then this action will render your post content.
     *
     * @param varchar $slug use for query by post name from post table.
     */
    
    public function actionPage($slug) {
        if (Yii::app()->user->isGuest && Common::getOptionValue('modulelist','member'))
            $this->layout = 'main-guest';
        $criteria = new CDbCriteria;
        $criteria->condition = 'post_name=:label';
        $criteria->params = array(':label' => $slug);
        $post = PostModel::model()->find($criteria);
        $this->render('view', array('model' => $post,));
    }
}
